<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <section>
        <ul>
            <li>
                <span>x(?=y)</span>
                <span></span>
            </li>
            <li>
                <span>(?<=y)x</span>
                <span></span>
            </li>
            <li>
                <span>x(?!y)</span>
                <span></span>
            </li>
            <li>
                <span>(?<!y)x</span>
                <span></span>
            </li>
        </ul>
    </section>
    <script>
        
        function execURL(url){
            const protocol = '(?<protocol>https?:)';
            const host = '(?<host>(?<hostname>[^/#?:]+)(:(?<port>\\d+))?)';
            const path = '(?<pathname>(\\/[^/#?]+)*\\/?)';
            const search = '(?<search>(\\?[^#]*)?)';
            const hash = '(?<hash>(#.*)?)';

            // const protocol = '(https?:)';
            // const host = '(([^/#?:]+)(:(\\d+))?)';
            // const path = '((\\/[^/#?]+)*\\/?)';
            // const search = '((\\?[^#]*)?)';
            // const hash = '((#.*)?)';

            // const protocol = '(?<protocol>https?:)';
            // const host = '(?<host>(?<hostname>[^/#?:]+)(?::(?<port>\\d+))?)';
            // const path = '(?<pathname>(?:\\/[^/#?]+)*\\/?)';
            // const search = '(?<search>(?:\\?[^#]*)?)';
            // const hash = '(?<hash>(?:#.*)?)';
            const reg = new RegExp(`^${protocol}\/\/${host}${path}${search}${hash}$`);
            const result = reg.exec(url);
            console.log(result);
            if(result){
                result.groups.port = result.groups.port || '';
                return result.groups;
            }
            return {
                protocol:'',host:'',hostname:'',port:'',
                pathname:'',search:'',hash:'',
            };
        }

        console.log(execURL('https://localhost:8080/?a=b#xxxx'));
    </script>
</body>
</html>